const mongoose = require('mongoose');

mongoose.connect('mongodb://127.0.0.1/class0331');

mongoose.connection.on('open',()=>{
    console.log('数据库链接成功');
    const studentSchema = new mongoose.Schema({
        name:String,
        age:Number,
        sex:String
    })
    const studentModel = mongoose.model('students',studentSchema);
    let p = new Promise((resolve, reject)=>{
        studentModel.find((err,data)=>{
            if(err){
                reject(err);
            }else{
                resolve(data);
            }
        })
    })
    p.then(value=>{
        console.log(value);
    },reason=>{
        console.log(reason);
    })
    
})